<!-- 审核微博 -->
<script setup>
import { ref, onMounted } from 'vue'
import { apiUsergetAllUser, apiUserUpdateState } from '@/api/admin.js'
import warningSvg from '@/assets/icons/warning.svg'
import arrowSvg from '@/assets/icons/arrow.svg'
const userList = ref()
const getData = async () => {
  const res = await apiUsergetAllUser()
  userList.value = res.data.data
  console.log(userList.value)
}
const load = () => {
  // 动态加载，想优化可以写
}
const changeState = num => {
  switch (num) {
    case 1:
      return '正常'
    case -1:
      return '封禁中'
  }
}
onMounted(() => {
  getData()
})
const banUserEvent = async name => {
  const res = await apiUserUpdateState({
    loginName: name,
    state: -1
  })
  getData()
  ElMessage.success('封禁成功')
}
const arrowUserEvent = async name => {
  const res = await apiUserUpdateState({
    loginName: name,
    state: 1
  })
  ElMessage.success('解封成功')
  getData()
}
</script>
<template>
  <ul
    v-infinite-scroll="load"
    class="infinite-list"
    style="overflow: auto; width: 1200px; margin-top: 90px"
  >
    <li style="margin-top: 20px" v-for="item in userList" :key="item.userId">
      <div class="container">
        <div class="header">
          <div class="imageIn">
            <img :src="item.photo" alt="" />
          </div>
          <div style="display: flex; flex-direction: column; width: 850px">
            <div style="font-size: 20px">
              {{ item.loginName }}
            </div>
            <div style="color: #797878">
              {{ item.nickname }}
            </div>
          </div>
          <div style="width: 100px">{{ changeState(item.state) }}</div>
          <img
            :src="arrowSvg"
            alt=""
            style="height: 50px; cursor: pointer"
            @click="arrowUserEvent(item.loginName)"
          />
          <img
            :src="warningSvg"
            alt=""
            style="height: 50px; cursor: pointer"
            @click="banUserEvent(item.loginName)"
          />
        </div>
      </div>
    </li>
  </ul>
</template>
<style lang="scss" scoped>
.imageIn {
  height: 50px;
  width: 50px;
  border-radius: 50%;
  display: flex;
  justify-content: center;
  align-items: center;
}
.header {
  width: 1150px;
  margin-top: 5px;
  display: flex;
  height: 50px;
  background-color: rgb(241, 241, 241);
  border-bottom: 1px solid #ccc;
  align-items: center;
}
.container {
  height: auto;
  width: 1200px;
  background-color: rgb(241, 241, 241);
  display: flex;
  flex-direction: column;
}
</style>
